package edu.wpi.first.wpilibj.templates.commands;

/**
 * This class encapsulates the methods and definitions needed to turn the
 * robot
 * @author anne
 */
public class Turn extends CommandBase {
    private double m_timeoutInSecs;
    
    /**
     * Constructor for the Turn class
     * @param timeoutInSecs Length of time the robot should spend turning 
     */
    public Turn(double timeoutInSecs) {
        /**
         * Since turning requires dedicated use of the chassis drive
         * train subsysytem, set that dependency here.
         */
        m_timeoutInSecs= timeoutInSecs;
        requires(chassis);
    }

    /**
     * This method is called right before the command is run the first time
     * so that variables can be initialized.  The reason "first time" is used
     * in this comment is that the command will be programmed to run once. 
     * However, the command may have its "execute" method called more than 
     * once by the scheduler until the command is completed (ie. in this case
     * the time out number of seconds have passed).  
     */
    protected void initialize() {
        setTimeout(m_timeoutInSecs);
    }

    /**
     * This method is called repeatedly when this Command is scheduled to run
     * It will call the chassis subsystem routine to turn. In this
     * command's case execute will repeatedly be called until the timeout
     * has expired.
     */
    protected void execute() {
        chassis.turnLeft(); // Turn robot left
    }

    /**
     * This method is called by the scheduler to see if the command has completed.
     * If the Command is not complete (ie. programmed amount of time hasn't passed) 
     * return false. Once the command is finished executing (programmed amount 
     * of time has passed)then this routine will return true to indicate that 
     * the scheduler can stop calling execute().
     */
    protected boolean isFinished() {
        /**
         * Since this command uses time to indicate when it has completed,
         * we check if enough time has passed.  The method isTimedOut will 
         * return true when the timeout has occurred and false otherwise.
         * So we can just return its return value.
         */
        return isTimedOut();
    }

    /**
     * This method is called once after isFinished returns true.  If there 
     * was any "cleanup" code needed after the command completes, we would
     * put it here.
     */
    protected void end() {
    }

    /** 
     * This method is called when another command which requires one or more of 
     * the same subsystems is scheduled to run. For example, if this command was
     * running and another command was scheduled to run which needed control 
     * of the drive train (chassis), that command would have marked chassis as
     * needed with a requires statement.  When the later command runs, it will 
     * interrupt this command and start running. When this happens, this 
     * method will be called since this command was not marked as non-interruptible.
     */
    protected void interrupted() {
    }
}
